package com.example.chesswithnet.Controller;

import com.example.chesswithnet.Dao.UserDao;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;

import java.sql.SQLException;

public class Register extends BaseController {

    @FXML
    private TextField account;
    @FXML
    private PasswordField password;
    @FXML
    private PasswordField confirmPass;
    @FXML
    private TextField mobilePhone;

    private String accountText;
    private String passwordText;
    private String confirmPassText;
    private String mobilePhoneText;
    private UserDao.registerEnum  registerEnum;

    public void onBtnRegisterClick() throws SQLException {
        accountText = account.getText();
        passwordText = password.getText();
        confirmPassText = confirmPass.getText();
        mobilePhoneText = mobilePhone.getText();
        if(accountText.trim().isEmpty())
            alert(Alert.AlertType.WARNING,"账号不能为空");
        else if(passwordText.trim().isEmpty())
            alert(Alert.AlertType.WARNING,"密码不能为空");
        else if(confirmPassText.trim().isEmpty())
            alert(Alert.AlertType.WARNING,"确认密码不能为空");
        else if(!passwordText.equals(confirmPassText))
            alert(Alert.AlertType.ERROR,"两次密码输入不一致");
//        else if (UserDao.registerEnum.ACCOUNT_EXIST == new UserDao().isExistAccount(accountText))
//            alert(Alert.AlertType.WARNING,"注册的账号已存在");
        else {
            registerEnum = new UserDao().register(accountText,passwordText,passwordText);
            if(registerEnum == UserDao.registerEnum.SUCCESS){
                alert(Alert.AlertType.INFORMATION,"注册成功");
            }else {
                alert(Alert.AlertType.ERROR,"注册失败");
            }
        }

    }

    public void onBtnResetClicke(){
        account.setText("");
        password.setText("");
        confirmPass.setText("");
        mobilePhone.setText("");
    }

}
